<?php

namespace App\Libs\Strategy;


class Context extends AContext
{

    public function create(array $data = [],$callable = false)
    {
        $this->callable = $callable;
        $this->__hook();
        return (new DataEntry(!empty($data)? $data :$this->data,$this->model))->algorithm();
    }


    public function update($id,array $data = [],$callable = false)
    {
        $this->callable = $callable;
        $this->__hook();
        return (new UpdateData(!empty($data)? $data :$this->data,$this->model,$id))->algorithm();
    }


    public function delete($id,$callable = false)
    {
        return (new DeleteData($this->model,$id,$callable))->algorithm();
    }

    /**
     * 展示数据 默认分页取出10条数据 传0展示所有数据
     * @param int $page
     */
    public function display($page = 10,$callable = false)
    {
        return (new DisplayData($page,$callable,$this->model))->algorithm();
    }

    public function find($id,$callable = false)
    {
        return (new FindData($id,$this->model))->algorithm();
    }

    public function setRules($rule, $msg = [])
    {
        $this->rules = $rule;
        $this->msg = $msg;
        $this->validate = true;
        return $this;
    }

    public function getModel()
    {
        return $this->model;
    }
}
